/*
 * @Author: zhangjingyu
 * @Date: 2020-12-25 11:08:56
 * @LastEditors: zhangjingyu
 * @LastEditTime: 2021-03-08 09:58:20
 * @FilePath: \vprisk-weifuwu\src\main.js
 * @Description: 
 */

import "core-js/stable";
import "regenerator-runtime/runtime";
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 先引入重置样式，后面文件可覆盖

// 全局配置
import '@/assets/scss/reset.scss'
import 'element-ui/lib/theme-chalk/index.css'
// 自定义icon
import '@/assets/scss/svg_icon.scss'
import HTTP from '@/api/config'
import './mock'
// 第三方包
import './lib/element'
import Contextmenu from "vue-contextmenujs"
Vue.use(Contextmenu);
// 自定义组件 
import ForMenu from './components/ForMenu.vue'
import pagination from './components/pagination.vue'
import treeSelect from './components/treeSelect.vue'
import upperTemplate from "./components/upperTemplate.vue"
import onlyOneSearch from "./components/onlyOneSearch.vue"
import vpTree from "./components/vpTree.vue"
// 引导组件
import VueTour from 'vue-tour'
require('vue-tour/dist/vue-tour.css')
Vue.use(VueTour);

Vue.component('ForMenu', ForMenu);
Vue.component('pagination', pagination);
Vue.component('treeSelect', treeSelect);
Vue.component('upperTemplate', upperTemplate);
Vue.component('onlyOneSearch', onlyOneSearch);
Vue.component('vpTree', vpTree);
 
 
// 自定义方法
import {getLabel,tableDataPick,deepClone,listToTree} from '@/lib/util'
Vue.prototype.$getLabel = getLabel // list翻译方法
Vue.prototype.$tableDataPick = tableDataPick // table列隐显控制方法
Vue.prototype.$clone = deepClone // 深拷贝方法
Vue.prototype.$listToTree = listToTree // 转树方法

// 窗口拖拽js
import './lib/drag'
// 样式 
import '@/assets/scss/index.scss'
// 以下为bpmn工作流绘图工具的样式
import 'bpmn-js/dist/assets/diagram-js.css' // 左边工具栏以及编辑节点的样式
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn.css'
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-codes.css'
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css'
import 'bpmn-js-properties-panel/dist/assets/bpmn-js-properties-panel.css' // 右边工具栏样式
// 将http对象挂载到Vue原型上，实现所有Vue实例都可以通过$http调用这个HTTP对象
Vue.prototype.$http = HTTP

Vue.config.productionTip = false

// 添加路由守卫拦截，判断用户登录状态以跳转到对应页面
router.beforeEach((to, from, next) => {
    let token = sessionStorage.getItem('loginToken') || null
  if (!token && to.name !== 'login') {
    next({ name: 'login' })
  } else {
    next()
  }
})
// 处理路由懒加载会偶发出现Loading chunk
router.onError((error) => {
  const pattern = /Loading chunk (\d)+ failed/g;
  const isChunkLoadFailed = error.message.match(pattern);
  console.log(isChunkLoadFailed,'/Loading chunk (\d)+ failed/g','路由懒加载找不到对应的moudle')
  if (isChunkLoadFailed) {
      window.location.reload();
  }else{
      console.log(error)
  }
});


new Vue({
  router,
  store,
  render: h => h(App),
  created() {
    store.commit('addMenu', router)
  }
}).$mount('#app')
